package main

import (
	"flag"
	"log"
	"net/http"
	"os"

	"git.oschina.net/sheldwu/redis"
	"gitee.com/sheldwu/httpdns/config"
	"gitee.com/sheldwu/httpdns/handler"
	"gitee.com/sheldwu/httpdns/util"
	"github.com/wangtuanjie/ip17mon"
)

var params []interface{}

type responseT struct {
	Msg    string `json:"msg"`
	Status int    `json:"status"`
}

func main() {
	flag.Parse()
	err := ip17mon.Init("./data/17monipdb.dat")

	if err != nil {
		log.Fatal(err)
	}

	logFile, err := os.Create("/home/logs/httpdns/httpdns.log")

	defer func() {
		logFile.Close()
	}()

	if err != nil {
		log.Fatal("open log file error", err.Error())
	}

	handler.Logger = log.New(logFile, "[Debug]", log.Ldate|log.Ltime|log.Lshortfile)

	go util.Init()

	redis.Init(config.RedisConfig)

	http.HandleFunc("/cabinet", handler.Cabinet)
	http.HandleFunc("/app", handler.App)
	err = http.ListenAndServe(":8899", nil)

	if err != nil {
		log.Fatal(err)
	}

}
